﻿<UserControl x:Class="MetaCase.GraphBrowser.GraphBrowser"
             xmlns:local="clr-namespace:MetaCase.GraphBrowser"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.10.0"
             mc:Ignorable="d" Name="MEGraphBrowser"
             Background="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowBackgroundKey}}" d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <HierarchicalDataTemplate x:Key="graphTemplate" DataType="{x:Type local:GraphViewModel}" ItemsSource="{Binding children}">
            <StackPanel Orientation="Horizontal" >
                <Image Source="Resources/graph_icon.png" Height="16" Width="16" SnapsToDevicePixels="True" Margin="0,0,2,0" RenderOptions.BitmapScalingMode="NearestNeighbor" />
                <TextBlock Text="{Binding Name}" Padding="2" />
            </StackPanel>
        </HierarchicalDataTemplate>
        <Style x:Key="ToolBarButton" TargetType="{x:Type Control}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Control}">
                        <Image Source="{Binding Path=(local:ToolBarButton.Image),
                            RelativeSource={RelativeSource FindAncestor,
                            AncestorType={x:Type Control}}}" 
                            Margin="2" Height="16" Width="16" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="NearestNeighbor" />
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.2" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Orientation="Horizontal"  Background="#BCC7D8">
            <Button Name="ButtonRunAutobuild" Style="{DynamicResource ToolBarButton}"
                    local:ToolBarButton.Image="Resources/run_generator_icon_2.png"
                    ToolTip="Run Autobuild for the Selected Graph"
                    BorderThickness="0"  Click="ButtonRunAutobuild_Click" />
            <Button Name="ButtonGenerateFromList" Style="{DynamicResource ToolBarButton}"
                    local:ToolBarButton.Image="Resources/select_generator_to_run_icon.png"
                    ToolTip="Select Generator to Run"
                    BorderThickness="0" Margin="2" Click="ButtonGenerate_Click" />
            <Separator Margin="2">
                <Separator.LayoutTransform>
                    <RotateTransform Angle="90" />
                </Separator.LayoutTransform>
            </Separator>
            <Button Name="ButtonOpenInMetaEdit" Style="{DynamicResource ToolBarButton}"
                    local:ToolBarButton.Image="Resources/open_graph_in_metaedit_icon.png" 
                    ToolTip="Open Selected Graph in MetaEdit+"
                    BorderThickness="0" Margin="2" Click="ButtonOpen_Click" />
            <Button Name="ButtonCreateGraph" Style="{DynamicResource ToolBarButton}"
                    local:ToolBarButton.Image="Resources/create_graph_icon.png"
                    ToolTip="Create a New Graph"
                    BorderThickness="0" Margin="2" Click="ButtonCreateGraph_Click" />
            <Separator Margin="2">
                <Separator.LayoutTransform>
                    <RotateTransform Angle="90" />
                </Separator.LayoutTransform>
            </Separator>
            <Button Name="ButtonUpdateList" Style="{DynamicResource ToolBarButton}"
                    local:ToolBarButton.Image="Resources/update_graph_list_icon.png"
                    ToolTip="Update the Graph View"
                    BorderThickness="0" Margin="2" Click="ButtonUpdate_Click" />
            <Button Name="ButtonOpenSettings" Style="{DynamicResource ToolBarButton}"
                    local:ToolBarButton.Image="Resources/settings_icon.png"
                    ToolTip="Open the Launch Parameter Window"
                    BorderThickness="0" Margin="2" Click="ButtonSettings_Click" />
            <Separator Margin="2">
                <Separator.LayoutTransform>
                    <RotateTransform Angle="90" />
                </Separator.LayoutTransform>
            </Separator>
            <ToggleButton Name="ButtonShowTypeName" Style="{DynamicResource ToolBarButton}"
                    local:ToolBarButton.Image="Resources/folder_explore.png"
                    ToolTip="Show/Hide Graph Type"
                    BorderThickness="0" Margin="2" Click="ButtonShowTypeName_Clicked" Background="Transparent">
            </ToggleButton>
        </StackPanel>
        <Grid Grid.Row="1" >
            <Grid Name="GraphView" >
                <TreeView Margin="10,10,12,12" Name="treeView1" ItemTemplate="{StaticResource graphTemplate}" 
                          SelectedItemChanged="treeView1_SelectedItemChanged" 
                          PreviewMouseDoubleClick="treeView1_PreviewMouseDoubleClick" 
                          PreviewMouseLeftButtonDown="treeView1_PreviewMouseLeftButtonDown" >
                    <TreeView.Resources>
                        <LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" EndPoint="0,1" StartPoint="0,0">
                            <GradientStop Color="#FFD9F4FF" Offset="0"/>
                            <GradientStop Color="#FF9BDDFB" Offset="1"/>
                        </LinearGradientBrush>
                        <LinearGradientBrush x:Key="{x:Static SystemColors.ControlBrushKey}" EndPoint="0,1" StartPoint="0,0">
                            <GradientStop Color="#FFEEEDED" Offset="0"/>
                            <GradientStop Color="#FFDDDDDD" Offset="1"/>
                        </LinearGradientBrush>
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black" />
                        
                        <ContextMenu x:Key="45Menu" StaysOpen="True">
                            <MenuItem Header="Open Graph in MetaEdit+" Click="ButtonOpen_Click"  >
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="Resources/open_graph_in_metaedit_icon.png" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <Separator />
                            <MenuItem Header="Run Autobuild" Click="ButtonRunAutobuild_Click">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="Resources/run_generator_icon_2.png" />
                                </MenuItem.Icon>
                            </MenuItem>
                        </ContextMenu>
                        <ContextMenu x:Key="50Menu" StaysOpen="True" HasDropShadow="True">
                            <MenuItem Header="Run Autobuild" Click="ButtonRunAutobuild_Click">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="Resources/run_generator_icon_2.png" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="Select Generator to Run" Click="ButtonGenerate_Click" >
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="Resources/select_generator_to_run_icon.png" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <Separator />
                            <MenuItem Header="Open Graph in MetaEdit+" Click="ButtonOpen_Click"  >
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="Resources/open_graph_in_metaedit_icon.png" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="Edit Graph Properties" Click="ButtonEditProperties_Click" >
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="Resources/edit_properties_icon.png" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="Create a New Graph" Click="ButtonCreateGraph_Click" >
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="Resources/create_graph_icon.png" />
                                </MenuItem.Icon>
                            </MenuItem>
                        </ContextMenu>
                    </TreeView.Resources>
                    <TreeView.ItemContainerStyle>
                        <Style TargetType="{x:Type TreeViewItem}" >
                            <Setter Property="IsExpanded" Value="{Binding IsNodeExpanded, Mode=TwoWay}" />
                            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                            <Setter Property="BorderThickness" Value="1" />
                            <Style.Triggers>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter Property="Background" Value="#DFEEFF" />
                                    <Setter Property="BorderBrush" Value="#84ACDD"/>
                                </Trigger>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="IsSelected" Value="True"/>
                                        <Condition Property="IsSelectionActive" Value="False"/>
                                    </MultiTrigger.Conditions>
                                    <Setter Property="BorderBrush" Value="LightGray"/>
                                </MultiTrigger>
                            </Style.Triggers>
                            <Style.Resources>
                                <Style TargetType="Border">
                                    <Setter Property="CornerRadius" Value="2"/>
                                </Style>
                            </Style.Resources>
                        </Style>
                    </TreeView.ItemContainerStyle>
                </TreeView>
            </Grid>
            <Grid Name="ErrorView" Background="#31000000">
                <StackPanel Margin="10,10,12,12" Name="stackPanel1" VerticalAlignment="Center" HorizontalAlignment="Center" >
                    <TextBlock FontSize="18" Margin="5" Padding="10">No API connection found.</TextBlock>
                    <Button Name="ButtonStartMetaEdit" Width="120" Height="30" Margin="5" Click="ButtonStartMetaEdit_Click">
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/GraphBrowser;component/Resources/16x16%208-bit.png" Width="16" Height="16" />
                            <TextBlock Padding="5,0,0,0">Start MetaEdit+</TextBlock>
                        </StackPanel>
                    </Button>
                </StackPanel>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
